package com.ljx.qqpro.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljx.qqpro.common.utils.Result;
import com.ljx.qqpro.dto.search.SearchInfo;
import com.ljx.qqpro.entity.ChatEntity;
import com.ljx.qqpro.entity.UserEntity;
import com.ljx.qqpro.service.ChatService;
import com.ljx.qqpro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private UserService userService;

    @Autowired
    private ChatService chatService;

    @GetMapping("/userAndChat/{searchContent}")
    public Result<SearchInfo> userAndChat(@PathVariable String searchContent){
        List<UserEntity> userList = userService.list(new QueryWrapper<UserEntity>().eq("username", searchContent).eq("status", 1));
        List<ChatEntity> chatList = chatService.list(new QueryWrapper<ChatEntity>().eq("chat_num", searchContent).eq("status", 1).eq("type", 2));

        SearchInfo searchInfo = new SearchInfo();
        searchInfo.setChatList(chatList);
        searchInfo.setUserList(userList);

        return Result.success(searchInfo, "搜索成功");
    }

}
